package com.study.array;

/**
 * @author ytj
 * @date 2022/1/10
 */
public class Method17 {
    public static void main(String[] args) {
        int[] nums={-7,-3,2,3,11};
        for (int i = 0; i < sortedSquares(nums).length; i++) {
            System.out.println(sortedSquares(nums)[i]);
        }
    }

    public static int[] sortedSquares(int[] nums) {
        int[] newArray=new int[nums.length];
        for (int i = 0; i < nums.length; i++) {
            newArray[i]=nums[i]*nums[i];
        }
        for (int i = 0; i < newArray.length; i++) {
            for(int j=0;j<newArray.length-1;j++){
                if(newArray[j]>newArray[j+1]){
                    int num=newArray[j];
                    newArray[j]=newArray[j+1];
                    newArray[j+1]=num;
                }
            }
        }
        return newArray;
    }
}
